<%@include file="../_include.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%--路径 /forum/manager/sections--%>
<head>
    <script src="${pageContext.request.contextPath}/resources/js/jquery-2.1.1.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>manager sections</title>
</head>
<body>

<h1>manager sections</h1>
<%--已有版块--%>

<table>
    <c:forEach items="${sectionList}" var="section">
        <tr>
            <td>${section.name}</td>
            <td>
                <button id="edit">编辑</button>
            </td>
            <td>
                <button onclick="delete_section(${section.sectionId})">删除</button>
            </td>
        </tr>
    </c:forEach>
</table>

<%--TODO 增加版块--%>
<div>
    <div id="add_section_area">
        版块名:<input type="text" id="sectionName">
        <button id="btn_add_section">添加</button>
    </div>
</div>

<%--现有版块列表 编辑--%>
<script type="text/javascript">
    $('document').ready(function () {
        var addBtn = $('div#btn_show_input');
        addBtn.click(function () {
            $('div#add_section_area').toggle();
        });

        $('#btn_add_section').click(function () {
            $.post('/forum/manager/section', 'sectionName=' + $('#sectionName').val(), function (data) {
                console.log(data);
                window.location.reload();
            });
        });
    });

    function delete_section(sectionId) {
        $.ajax({
            url: '/forum/manager/section/' + sectionId,
            type: 'DELETE',
            success: function (data) {
                console.log(data);
                window.location.reload();
            }
        });
    }
</script>

</body>
</html>
